export default {
	namespaced: true,
	state: () => ({
		address: JSON.parse(uni.getStorageSync('address') || '{}'),
		// 登录成功之后的 token 字符串
		// token: uni.getStorageSync('token') || '',
		token: '1',
		userinfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'),
		redirectInfo: null
	}),
	mutations: {
		updateAddress(state,address) {
			state.address = address
			this.commit('my_user/saveAddressToStorage')
		},
		saveAddressToStorage(state) {
			uni.setStorageSync('address',JSON.stringify(state.address))
		},
		updateUserInfo(state,userinfo) {
			state.userinfo = userinfo
			// 通过 this.commit() 方法，调用 m_user 模块下的 saveUserInfoToStorage 方法，将 userinfo 对象持久化存储到本地
			this.commit('my_user/saveUserInfoToStorage')
		},
		saveUserInfoToStorage(state) {
			uni.setStorageSync('userinfo',JSON.stringify(state.userinfo))
		},
		// 更新token字符串
		updateToken(state,token) {
			state.token = token
			this.commit('my_user/saveTokenToStorage')
		},
		saveTokenToStorage(state) {
			uni.setStorageSync('token',state.token)
		},
		// 登陆后重定向回页面
		updateRedirectInfo(state,redirectInfo) {
			state.redirectInfo = redirectInfo
		}
	},
	getters: {
		addressStr(state) {
			return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
		}
	}
}